package com.tuangou.tuangougoods.goods.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.tuangou.tuangougoods.goods.entity.GoodsEntity;
import com.tuangou.tuangougoods.goods.service.GoodsService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;

/**
 * 
 *
 * @author zjb
 * @email zjb@tuangou.com
 * @date 2021-06-17 09:29:17
 */
@RestController
@RequestMapping("goods/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 单列表
     */
    @RequestMapping("/list")
    public R list(){

        List<GoodsEntity> entities = goodsService.list();

        return R.ok().put("date", entities);
    }

    /**
     * 条件查询加分页列表
     */
    @RequestMapping("/listpage")
    public R queryPageByCondition(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPageByCondition(params);
        return R.ok().put("page", page);
    }

    /**
     * 根据库存查询已售空界面
     */
    @RequestMapping("/findsk")
    //@RequiresPermissions("product:spuinfo:list")
    public R findsk(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{goodsId}")
    //@RequiresPermissions("goods:goods:info")
    public R info(@PathVariable("goodsId") Integer goodsId){
		GoodsEntity goods = goodsService.getById(goodsId);

        return R.ok().put("goods", goods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("goods:goods:save")
    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("goods:goods:update")
    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("goods:goods:delete")
    public R delete(@RequestBody Integer[] goodsIds){

		goodsService.removeByIds(Arrays.asList(goodsIds));

        return R.ok();
    }



}
